/* EasyCODE V8 */
/* EasyCODE ( 0 */
#include "JI2C.h"
#include "HMC5883L.h"
/* EasyCODE ( 0 
unsigned char HMC5883LRead(unsigned char address) */
/* EasyCODE F */
unsigned char HMC5883LRead(unsigned char address)
{
    unsigned char data;
    
    i2c_start();
    i2c_write(HMC5883L_W);	// write 0x3C
    i2c_write(address);	// write register address
    
    i2c_repStart();
    i2c_write(HMC5883L_R);	// write 0x3D
    data = i2c_read();	// Get MSB result
    i2c_nack();
    i2c_stop();
    return data;
}

/* EasyCODE ) */
/* EasyCODE ( 0 
void HMC5883LWrite(unsigned char address, unsigned char data) */
/* EasyCODE F */
void HMC5883LWrite(unsigned char address, unsigned char data)
{
    i2c_start();
    i2c_write(HMC5883L_W);	// write 0x3C
    i2c_write(address);	// write register address
    i2c_write(data);
    i2c_stop();
}

/* EasyCODE ) */
/* EasyCODE ( 0 
void HMC5883L(float*CX, float *CY, float *CZ) */
/* EasyCODE F */
void HMC5883L(float*CX, float *CY, float *CZ)
{
    signed short data;
    i2c_start();
    i2c_write(HMC5883L_W);	// write 0x3C
    i2c_write(HMC5883L_RA_DATAX_H);	// write register address
    
    i2c_repStart();
    i2c_write(HMC5883L_R);	// write 0xD1
    
    data=((i2c_read())<<8);
    i2c_ack();
    *CX=data+(i2c_read());
    i2c_ack();
    data=((i2c_read())<<8);
    i2c_ack();
    *CZ=data+(i2c_read());
    i2c_ack();
    data=((i2c_read())<<8);
    i2c_ack();
    *CY=data+(i2c_read());
    i2c_nack();
    i2c_stop();
    
    *CX=*CX/1090;
    *CY=*CY/1090;
    *CZ=*CZ/1090;
}

/* EasyCODE ) */
/* EasyCODE ) */
